cmake_minimum_required(VERSION 3.10)

# 忽略代码中的中文注释引起的MSVC编译器警告
if(MSVC)
    add_compile_options(/source-charset:utf-8)
    add_compile_options(/execution-charset:utf-8)
endif()

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)


set(PROJECT_NAME "example00")
project(${PROJECT_NAME} VERSION 1.0.0)

find_package(OpenGL REQUIRED COMPONENTS OpenGL)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets REQUIRED)
find_package(GLEW REQUIRED)
find_package(Poco REQUIRED COMPONENTS Foundation)

if(MSVC)
    # pcl
    find_package(PCL REQUIRED)
else()
    find_package(rs_driver REQUIRED)
    set(PCL_DIR "/home/school/lib/pcl-1.13/share/pcl-1.13")
    find_package(PCL 1.13.1 REQUIRED)
endif()

CollectSourceFiles(${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES)
add_executable(${PROJECT_NAME} ${PRIVATE_SOURCES})

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/libs/include ${PCL_INCLUDE_DIRS})

#连接依赖库
if(MSVC)
    target_link_libraries(${PROJECT_NAME} PUBLIC
    $<$<CONFIG:Debug>:${CMAKE_SOURCE_DIR}/libs/lib/isc-lib-lidard.lib>
    $<$<CONFIG:Release>:${CMAKE_SOURCE_DIR}/libs/lib/isc-lib-lidar.lib>
    )
elseif(UNIX AND NOT APPLE)
    target_link_libraries(${PROJECT_NAME} PUBLIC
    $<$<CONFIG:Debug>:${CMAKE_SOURCE_DIR}/libs/lib/libisc-lib-lidard.so>
    $<$<CONFIG:Release>:${CMAKE_SOURCE_DIR}/libs/lib/libisc-lib-lidar.so>
    )
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE ${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets OpenGL::GL GLEW::GLEW Poco::Foundation)

if(MSVC)
    # 定义需要查找的多个目录
    set(DLL_DIRECTORIES
        ${CMAKE_SOURCE_DIR}/libs/bin
    )
    # copy dll files
    CopyFiles("${PROJECT_NAME}" "${DLL_DIRECTORIES}" "*.dll" $<TARGET_FILE_DIR:${PROJECT_NAME}> PRIVATE_SOURCES)
endif()